package com.talkweb.osmharmony.tileprovider.util;

import com.talkweb.osmharmony.tileprovider.IRegisterReceiver;
import com.talkweb.osmharmony.util.Log;
import ohos.app.Context;
import ohos.event.commonevent.CommonEventManager;
import ohos.event.commonevent.CommonEventSubscriber;
import ohos.rpc.RemoteException;

public class SimpleRegisterReceiver implements IRegisterReceiver {

    private static final String TAG = SimpleRegisterReceiver.class.getSimpleName();

    private Context mContext;

    public SimpleRegisterReceiver(final Context pContext) {
        super();
        mContext = pContext;
    }

    @Override
    public void registerReceiver(CommonEventSubscriber subscriber) {
        try {
            CommonEventManager.subscribeCommonEvent(subscriber);
        } catch (RemoteException e) {
            e.printStackTrace();
            Log.w(TAG, "registerReceiver ====>", e);
        }
    }

    @Override
    public void unregisterReceiver(CommonEventSubscriber subscriber) {
        try {
            CommonEventManager.unsubscribeCommonEvent(subscriber);
        } catch (RemoteException e) {
            e.printStackTrace();
            Log.w(TAG, "unregisterReceiver ====>", e);

        }
    }

    @Override
    public void destroy() {
        mContext = null;
    }
}
